package com.jemmyee.pizza.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import org.springframework.orm.hibernate3.SessionFactoryUtils;
import org.springframework.stereotype.Repository;

import com.jemmyee.core.dao.BaseDaoImpl;
import com.jemmyee.pizza.entity.Apply;

@Repository("applyDao")
public class ApplyDaoImpl extends BaseDaoImpl<Apply> implements IApplyDao{

	public List<List<String>> queryByJDBC(String sql,int columnAmount){
		System.out.println(sql);
		Connection conn = null ;
		Statement stat = null ;
		ResultSet rs = null ;
		List<List<String>> result = new ArrayList<List<String>>();
		try {
			conn = SessionFactoryUtils.getDataSource(getSessionFactory()).getConnection();
			stat = conn.createStatement();
			rs = stat.executeQuery(sql);
			while(rs.next()){
				List<String> row = new ArrayList<String>();
				for(int i = 0 ; i < columnAmount ; i++){
					row.add(rs.getString(i+1));
				}
				result.add(row);
			}
		} catch (SQLException e) {
			System.err.println(e.getMessage());
			System.err.println("查询出错，请检查sql语句,以及 columnAmount 是否超出了sql语句所查询出的列数!");
		} finally {
			try {
				if(rs != null)rs.close();
				if(stat != null)stat.close();
				if(conn != null)conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return result ;
	}
}
